<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
include APPLICATION_PATH."/models/base/AdminBase.php";
class Model_Admin extends Model_AdminBase{
    
}
class Model_AdminMapper extends Model_AdminMapperBase{
     public function fetchAll_KD_USER($user_id){
        $db = Zend_Db_Table::getDefaultAdapter();
        $select="select t3.id,t3.user_name,t3.password,t3.email,t3.phone,t3.first_name,t3.last_name,t3.created,t3.created_by,t3.modified,t3.modified_by,t3.status,t3.order,t3.birthday,t3.admin_group_id from agent as t1 right join admin_area as t2 on t1.area_id = t2.area_id right join admin as t3 on t2.admin_id=t3.id where t1.user_id ='".$user_id."'group by t3.id";        
        $stmt=$db->query($select);
        $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $entries = array();
        foreach ($rows as $row){
            $entry = new Model_Admin();
            $entry->setId($row->id)
                   ->setId($row->id)
                    ->setUserName($row->user_name)
                    ->setPassword($row->password)
                    ->setFirst_Name($row->first_name)
                    ->setLast_Name($row->last_name)
                    ->setPhone($row->phone)
                    ->setCreated($row->created)
                    ->setCreated_By($row->created_by)
                    ->setModified($row->modified)
                    ->setModified_By($row->modified_by)
                    ->setBirthday($row->birthday)
                    ->setOrder($row->order)
                    ->setStatus($row->status)
                    ->setEmail($row->email)
                    ->setAdmin_Group_Id($row->admin_group_id);
            $entries[]=$entry;
        }
        return $entries;
    }
    
    public function findbyusername($username){
        $db = Zend_Db_Table::getDefaultAdapter();
        $select= "select max(id) as id from admin where user_name='$username'";
        $stmt=$db->query($select);
        $row = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        if($row==NULL){
            return 1;
        } else {
            return $row[0]->id;
        }
    }
   
}
